x, y = input().split()
print(x, y)
for _ in range(int(input())):
a, b = input().split()
if x == a:
x = b
elif y == a:
y = b
print(x, y)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define pb push_back
#define endl '\n'
#define all(v) v.begin(), v.end()
#define fr(m,n) for(i=m;i<n;i++)
#define frr(m,n) for(i=m-1;i>=n;i--)
#define ffr1 for(i=n;i>=1;i--)
#define ffr for(i=n-1;i>=0;i--)
#define ff for(i=0;i<n;i++)
#define ff1 for(i=1;i<=n;i++)
#define frj(m,n) for(j=m;j<n;j++)
#define frl(m,n) for(l=m;l<n;l++)
#define frd(m,n) for(d=m;d<n;d++)
#define yes cout << "YES"
#define no cout << "NO"
#define yesm cout << "Yes"
#define nom cout << "No"
#define inf INT_MAX
#define ext {cout << -1; return;}
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define rall(a) a.rbegin(),a.rend()
#define vi vector<int>
#define pi pair<int,int>
#define vvi vector<vi>
#define vc vector<char>
#define vb vector<bool>
#define vs vector<string>
#define ss set<string>
#define vpi vector<pi>
#define mii map<int,int>
#define mci map<char,int>
#define als(i) cout << i.fi << " " << i.se << endl
#define si set<int>
#define sc set<char>
#define fi first
#define wq while(q--)
#define se second
#define sz size()
#define el cout<<endl
bool id = 0, id1 = 0, id2 = 0;
int x = 0, y = 0, z = 0, type, tp;
int ans = 0, num = 0, sum = 0, mo = 0, me = 0, cnt = 0, mi = inf, ma = 0;
string s, p, st;
int h = 0, w = 0, n = 0, m = 0, t = 0, k = 0, i = 0, j = 0, l = 0, r = 0, q = 0, a = 0, b = 0, c = 0, d = 0;
const int mod = 1e9 + 7;
// const int mod = 998244353;
ll fac(ll n) {ll ans = 1; for (int i = 1; i <= n; ++i) {ans = ans * i;} return ans;}
bool cprime(ll n) {if (n <= 1)return false; if (n <= 3)return true; if (n % 2 == 0 || n % 3 == 0)return false; for (int i = 5; i * i <= n; i = i + 6)if (n % i == 0 || n % (i + 2) == 0)return false; return true;}
int binpow(int x, int y) {int z = 1; while (y) {if (y & 1) z = z * x % mod; x = x * x % mod; y >>= 1;} return z;}
int inv(int x) {return binpow(x, mod - 2);}
int bintoint(string s) {reverse(all(s)); int xx = 0; int m = 1; frj(0, s.sz) {xx += (s[j] == '1' ? m : 0); m <<= 1;} return xx;}
string inttobin(int x) {string s; while (x) {s += (x & 1) + '0';} reverse(all(s)); return s;}
void solve() {
cin >> s >> p;
// string q;
cin >> n;
set<string>q;
q.insert(s);
q.insert(p);
for (auto l : q) cout << l << " "; el;
ff{
cin >> s >> p;
if (q.find(s) != q.end()) {
q.erase(s);
q.insert(p);
}
else{
q.erase(p);
q.insert(s);
}
for (auto l : q) cout << l << " "; el;
}
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
int T = 1;
// cin >> T;
while (T--) {
cout << fixed << setprecision(12); solve();
cout << endl;
} return 0;
}
961A - Tetris | 1635B - Avoid Local Maximums |
20A - BerOS file system | 1637A - Sorting Parts |
509A - Maximum in Table | 1647C - Madoka and Childish Pranks |
689B - Mike and Shortcuts | 379B - New Year Present |
1498A - GCD Sum | 1277C - As Simple as One and Two |
1301A - Three Strings | 460A - Vasya and Socks |
1624C - Division by Two and Permutation | 1288A - Deadline |
1617A - Forbidden Subsequence | 914A - Perfect Squares |
873D - Merge Sort | 1251A - Broken Keyboard |
463B - Caisa and Pylons | 584A - Olesya and Rodion |
799A - Carrot Cakes | 1569B - Chess Tournament |
1047B - Cover Points | 1381B - Unmerge |
1256A - Payment Without Change | 908B - New Year and Buggy Bot |
979A - Pizza Pizza Pizza | 731A - Night at the Museum |
742A - Arpa’s hard exam and Mehrdad’s naive cheat | 1492A - Three swimmers |